<!--  -->
<template>
  <div>
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择年月日"
        :min-date="minDate"
        :max-date="maxDate"
        @confirm='onConfirm'
        @cancel='$emit("close")'
      />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
import dayjs from 'dayjs'
export default {
  name: 'EditBirthday',
  props: {
    modelValue: {
      tyep: String,
      required: true
    }
  },
  data () {
    return {
      currentDate: new Date(this.modelValue),
      minDate: new Date(1900, 0, 1),
      maxDate: new Date()
    }
  },
  methods: {
    onConfirm (value) {
      // 日期格式化
      const data = dayjs(value).format('YYYY-MM-DD')
      updateUserProfile({ birthday: data }).then(res => {
        this.$emit('update:modelValue', res.data.data.birthday)
        this.$emit('close')
      }).catch(err => {
        console.log(err)
      })
    }
  }
}
</script>

<style  scoped>

</style>
